home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / coreaids.zip / SEARCH.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  2KB  |  98 lines

  1. ;    DESC:    Searches for a string in the indicated buffer        V1.02
  2. ;    IN:    *{DIR} direction of search (0:forward,1-FFFF:reverse)
  3. ;        *{SEG_VAL} segment and
  4. ;        *{OFFSET} offset of buffer to search
  5. ;        *{LENGTH} length of search string
  6. ;        *{SSTRNG} segment and
  7. ;        *{OSTRNG} offset of search string
  8. ;    OUT:    *{OSEG} segment and
  9. ;        *{OOFF} of search string (both zero if not found)
  10. ;    SAMPLE:    Callm    SEARCH,<DIR,SEG_VAL,OFFSET,LENGTH,SSTRNG,OSTRNG>,
  11. ;                       <OSEG,OOFF>
  12. ;    ####################################################################
  13.  
  14.     Extrn    PUSHALL:Near
  15.     Extrn    POPALL:Near
  16.     Extrn    SCAN_BYT:Near
  17.  
  18.  
  19. SEARCHC    Segment
  20.     Assume    CS:SEARCHC
  21.     Public    SEARCH
  22.  
  23.     Include    CALLM.MAC
  24.                         ;notice.
  25.     DB    'SEARCH   - V1.02, Copyright 1987, CoreTechs   ',0DH,0AH
  26.  
  27. SEARCH    Proc    Near
  28.     Call    PUSHALL                ;save registers.
  29.  
  30.     Pop    SI                ;recover offset and
  31.     Pop    DS                ;segment of search string.
  32.  
  33.     Mov    BP,SI
  34.     Mov    AH,0
  35.     Mov    AL,DS:BYTE PTR[BP]        ;get first char. of string.
  36.  
  37.     Pop    BP                ;recover length of string.
  38.  
  39.     Pop    BX                ;recover offset and
  40.     Pop    DX                ;segment of search buffer.
  41.  
  42. T1:    Pop    CX                ;recover search direction.
  43.     Jcxz    FORWRD                ;if 0, then search forward.
  44.  
  45.     Std                    ;other then 0, reverse search.
  46.     Jmp    S1                ;start search
  47.  
  48. FORWRD:    Cld
  49.  
  50. S1:    Callm    SCAN_BYT,<DX,BX,AX,1>,<BX,BX>    ;locate start of string.
  51.  
  52.     Cmp    BX,0                ;exit if no match
  53.     JZ    DONE2
  54.     Cmp    BX,0FFFFH
  55.     JZ    DONE2
  56.  
  57.     Mov    DI,BX                ;setup for compare and
  58.     Jcxz    FOR1                ;possible additional searches.
  59.     Dec    BX
  60.     Jmp    CON1
  61.  
  62. FOR1:    Inc    BX
  63.  
  64. CON1:    Push    CX                ;store direction.
  65.     Cld                    ;and clear for compare.
  66.  
  67.     Mov    CX,BP                ;length of string.
  68.     Mov    ES,DX                ;segment of buffer.
  69.     Push    SI
  70.     Repz    CMPSB                ;see if this is the string.
  71.     Pop    SI
  72.  
  73.     Jcxz    DONEP                ;search is possibly complete.
  74.     Jmp    T1
  75.  
  76. DONEP:    Jz    DONE                ;search is done.
  77.     Jmp    T1
  78.     
  79. DONE:    Pop    CX
  80.     Jcxz    FOR2
  81.     Inc    BX
  82.     Jmp    CON2
  83.  
  84. DONE2:    Mov    BX,0
  85.     Mov    DX,0
  86.     Jmp    CON2
  87.  
  88. FOR2:    Dec    BX
  89. CON2:    Push    BX                ;return search results.
  90.     Push    DX
  91.  
  92.     Call    POPALL                ;recover registers.
  93.     Ret
  94.  
  95. SEARCH    Endp
  96. SEARCHC    Ends
  97.     End
  98.